package thread;

import java.util.concurrent.*;

/**
 * 创建线程方式3
 *
 * @author dingwen
 * @date 2021/08/30
 */
public class CreateThread3 implements Callable<Boolean> {
    @Override
    public Boolean call() throws Exception {
        System.out.println("新的线程创建成功");
        return true;
    }

    public static void main(String[] args){

        try {
            System.out.println("main 线程");
            System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
            CreateThread3 thread3 = new CreateThread3();
            // 创建执行线程服务
            // 指定线程池大小为1
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            // 提交执行
            Future<Boolean> submit = executorService.submit(thread3);
            System.out.println("submit.get() = " + submit.get());
            // 关闭
            executorService.shutdownNow();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
